package com.example.demo.mbp.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.mbp.BeanToQueryWrapper;
import com.example.demo.mbp.entity.CommonQueryRequest;


/**
 *
 * @param <M>
 * @param <T>
 */
public class BaseService<M extends BaseMapper<T>, T extends Object> extends ServiceImpl<M, T> {

    public Page<T> queryByCondition(CommonQueryRequest request) {
        // 创建分页对象
        Page<T> page = new Page<>(request.getPageNum(), request.getPageSize());

        QueryWrapper<T> wrapper = BeanToQueryWrapper.queryByCondition(request,this.getEntityClass());
        // 执行查询
        page = this.page(page, wrapper);
        return page;
    }
}